package com.mobile.widget;

import com.mobile.aide.ui.R;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;

public class PushSmsReceiverBaseLayout<T extends BaseAdapter> extends LinearLayout{
	private Context          		 mContext;
	private ListView 				 mAppListView;
	private T						 mAdapter;
	private int                      mListViewId;

	private ListScrollListener mListScrollListener;

	public PushSmsReceiverBaseLayout(Context context) {
		super(context);
	}
	
	public PushSmsReceiverBaseLayout(Context context,
									 AttributeSet attrs) {
		super(context, attrs);
	}
	
	public void setAdapter(T adapter) {
		mAdapter = adapter;
	}
	
	public void setListViewId(int id) {
		mListViewId = id;
	}
	
	public void init() {
		mAppListView = (ListView)findViewById(R.id.show_app_list);
		mAppListView.setAdapter(mAdapter);
		mAppListView.setDivider(new ColorDrawable(Color.TRANSPARENT));
		mAppListView.setOnScrollListener(new AbsListView.OnScrollListener() {
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				
			}

			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				if (mListScrollListener != null && visibleItemCount > 0) {
					mListScrollListener.onListScroll(firstVisibleItem, firstVisibleItem + visibleItemCount - 1);
				}
			}
		});
	}

	public LinearLayout getLayout() {
		return this;
	}

	public ListView getmAppListView() {
		return mAppListView;
	}

	public void setmAppListView(ListView mAppListView) {
		this.mAppListView = mAppListView;
	}

	public void setListScrollListener(ListScrollListener listener) {
		mListScrollListener = listener;
	}

	public interface ListScrollListener {
		public void onListScroll(int first, int last);
	}
}
